package Day8Zuoye;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Test3 {
    public static void main(String[] args) {
        Test3 address = new Test3();
        String domain = "sina.com";
        System.out.println("要获取域名的地址为: " + domain);
        InetAddress[] array = address.getServerIP(domain);
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            System.out.println("ip：" + i + "--》" + array[i].getHostAddress());
            count++;
        }
        System.out.println("该域名解析到IP: " + count);
    }
    /**
     * 获得某域名的IP地址
     */
    public InetAddress[] getServerIP(String domain) {
        InetAddress[] myServer = null;
        try {
            myServer = InetAddress.getAllByName(domain);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return myServer;
    }
    }

